#include "StdAfx.h"
#include ".\taproom.h"

CTaproom::CTaproom(void)
{
	this->employCost = 100;
}

CTaproom::~CTaproom(void)
{
}

TMessage * CTaproom::DoMsg(CPlayerSession &player, TMsgHead *msg)
{
	switch(msg->ID)
	{
	case EmploySailor:
		if (msg->len == sizeof(TMsgHead) + sizeof(msgEmploySailor) + 3)
		{
			msgEmploySailor * emsg = (msgEmploySailor *)((char *)msg + sizeof(TMsgHead));
			return this->Employ(player, emsg);
		}
		break;
	default:
		break;
	}
	return NULL;
}

TMessage * CTaproom::Employ(CPlayerSession &player, msgEmploySailor *msg)
{
	static TMessage re;
	int Result;
	Result = player.Employ(this->employCost, msg->num);
	if (Result == EmploySailorOK)
	{
		re = CreateMsgEmploySailorOK(player.userID, msg->num);
	}
	else
	{
		re = MakeNullMsg(player.userID, TaproomMsg, Result);
	}
	return &re;
}
 
TMessage * CTaproom::EnterTaproom(CPlayerSession &player, msgEnter *msg)
{
	if (msg->sceneID != TAPROOM)
		return NULL;
	if (player.GetState() != CITY)
		return NULL;
	player.SetState(TAPROOM);

	static TMessage re;
	re = CreateMsgEmployCost(player.userID, this->employCost);
	return &re;
}

TMessage * CTaproom::QuitTaproom(CPlayerSession &player)
{
	if (player.GetState() != TAPROOM)
		return NULL;
	player.SetState(CITY);

	static TMessage re;
	re = CreateMsgQuitConfirm(player.userID);
	return &re;
}